<?php


namespace apps\marriage\core\service;


use apps\marriage\core\logic\FileLogic;
use apps\marriage\core\logic\WeixinMpLogic;
use apps\marriage\core\model\SystemNotice;
use apps\marriage\core\model\User;
use apps\marriage\core\model\UserPlatform;
use apps\marriage\core\model\UserSystemNotice;
use apps\marriage\core\logic\RegionLogic;
use apps\marriage\core\model\MemberProfile;
use apps\marriage\core\model\MemberProfileExchangeApply;
use apps\marriage\core\model\MemberRechargeRecord;
use think\Exception;
use think\facade\Log;
use vm\com\BaseService;
use vm\org\Coreseek;
use vm\org\lock\DisLockFactory;
use vm\org\queue\QueueFactory;

class MemberProfileService extends BaseService
{
    /**
     * @var RegionLogic
     */
    private $regionLogic;

    protected function init()
    {
        parent::init();
        $this->regionLogic = logic('Region', LOGIC_NAMESPACE);
    }

    /**
     * @return FileLogic
     */
    private function getFileLogic()
    {
        return logic('File', LOGIC_NAMESPACE);
    }

    /**
     * @return MemberProfile
     */
    protected function getModel()
    {
        return new MemberProfile();
    }

    /**
     * @return MemberRechargeRecordService
     */
    protected function getMemberRechargeRecordService()
    {
        return service('MemberRechargeRecord', SERVICE_NAMESPACE);
    }

    /**
     * @return UserService
     */
    protected function getUserService()
    {
        return service('User', SERVICE_NAMESPACE);
    }

    /**
     * @return BaseService|SiteConfigService
     */
    protected function getSiteConfigService()
    {
        return service('SiteConfig', SERVICE_NAMESPACE);
    }

    /**
     * @return MemberProfileExchangeApplyService
     */
    protected function getMemberProfileExchangeApplyService()
    {
        return service('MemberProfileExchangeApply', SERVICE_NAMESPACE);
    }

    /**
     * @return SystemNoticeService
     */
    protected function getSystemNoticeService()
    {
        return service('SystemNotice', SERVICE_NAMESPACE);
    }

    /**
     * @return UserSystemNoticeService
     */
    protected function getUserSystemNoticeService()
    {
        return service('UserSystemNotice', SERVICE_NAMESPACE);
    }

    /**
     * @return UserPlatformService
     */
    protected function getUserPlatformService()
    {
        return service('UserPlatform', SERVICE_NAMESPACE);
    }

    /**
     * @return WeixinMpLogic
     */
    private function getWeixinMpLogic()
    {
        return  Logic('WeixinMp', LOGIC_NAMESPACE);
    }

    public function delete(array $params)
    {
        $member = $this->info($params);
        if($this->update(['marriage_seeking_status' => 0], $params)
            && $this->getUserService()->deleteByPk($member['user_id'])) {
            return true;
        }
        throw new Exception('删除失败');
    }

    public function createByAdmin(array $user, array $member)
    {
        if(empty($user['mobile'])) {
            while(true) {
                $user['mobile'] = '000' . rand_string(8, 1);
                if(!$this->getUserService()->info(['mobile' => $user['mobile']])) {
                    break;
                }
            }
        }
        $user['intro'] = '';
        $member['user_id'] = $this->getUserService()->create($user);
        $memberId = $this->create($member);
        return [
            'user_id' => $member['user_id'],
            'member_id' => $memberId
        ];
    }

    public function getByUserId($userId)
    {
        return $this->info(['user_id' => $userId]);
    }

    public function updateByUserId($userId, array $data)
    {
        if($this->update($data, ['user_id' => $userId])) {
            return true;
        }
        throw new Exception('更新失败');
    }

    public function updateVipLevel($userId, $vipLevel, $duration = null)
    {
        $site = config('site');
        $vipLevels = $site['vip_levels'];
        $vipLevelItem = $vipLevels[$vipLevel];
        $memberProfile = $this->getByUserId($userId);
        $nowtime = time();
        if($memberProfile['vip_level'] > $vipLevel && $memberProfile['vip_level_end_time'] > $nowtime) {
            throw new Exception('您当前已是【'.$vipLevels[$memberProfile['vip_level']]['name'].'】，无法升级为【'.$vipLevelItem['name'].'】');
        }
        if(is_null($duration)) {
            $duration = $vipLevelItem['rights']['duration'];
        }
        if ($memberProfile['vip_level'] == $vipLevel && $memberProfile['vip_level_end_time'] > $nowtime) {
            $data = [
                'vip_level_end_time' => $memberProfile['vip_level_end_time'] + $duration,
                'wxid_view_amount' => $memberProfile['wxid_view_amount'] + $vipLevelItem['rights']['items']['unlock_wxid_present_amount'],
                'phone_view_amount' => $memberProfile['phone_view_amount'] + $vipLevelItem['rights']['items']['unlock_phone_present_amount'],
                'join_offline_activity_amount' => $memberProfile['join_offline_activity_amount'] + $vipLevelItem['rights']['items']['join_offline_activity_amount'],
                'mp_recommend_amount' => $memberProfile['mp_recommend_amount'] + $vipLevelItem['rights']['items']['mp_publish_match_marriage_articles'],
                'live_video_recommend_amount' => $memberProfile['live_video_recommend_amount'] + $vipLevelItem['rights']['items']['live_video_room_recommend_amount'],
            ];
        } else {
            $data = [
                'vip_level' => $vipLevel,
                'vip_level_begin_time' => $nowtime,
                'vip_level_end_time' => $nowtime + $duration,
                'wxid_view_amount' => $memberProfile['wxid_view_amount'] + $vipLevelItem['rights']['items']['unlock_wxid_present_amount'],
                'phone_view_amount' => $memberProfile['phone_view_amount'] + $vipLevelItem['rights']['items']['unlock_phone_present_amount'],
                'join_offline_activity_amount' => $memberProfile['join_offline_activity_amount'] + $vipLevelItem['rights']['items']['join_offline_activity_amount'],
                'mp_recommend_amount' => $memberProfile['mp_recommend_amount'] + $vipLevelItem['rights']['items']['mp_publish_match_marriage_articles'],
                'live_video_recommend_amount' => $memberProfile['live_video_recommend_amount'] + $vipLevelItem['rights']['items']['live_video_room_recommend_amount'],
            ];
        }
        return $this->updateByUserId($userId, $data);
    }

    /**
     * 修改形象照
     * @param $userId
     * @param $photo
     * @return bool
     * @throws Exception
     */
    public function modifyPhoto($userId, $photo)
    {
        $member = parent::info(['user_id' => $userId]);
        if($member['realname_auth_status'] == 0) {
            throw new Exception('请先完成实名认证');
        }
        $data = [
            'auditing_photo' => $photo,
            'photo_audit_status' => MemberProfile::PHOTO_AUDIT_STATUS_AUDITING
        ];
        $where = [
            'user_id' => $userId,
            'realname_auth_status' => 1
        ];
        if($this->update($data, $where)) {
            return true;
        }
        throw new Exception('修改失败');
    }

    public function onAuditPhoto($id, $status)
    {
        $profile = parent::getByPk($id);
        $data = [];
        if($status == MemberProfile::PHOTO_AUDIT_STATUS_APPROVED) {
            $data['photo'] = $profile['auditing_photo'];
            $data['auditing_photo'] = 0;
            $data['photo_audit_status'] = 0;
        } else {
            $data['photo_audit_status'] = $status;
        }
        return $this->update($data, [
            'id' => $id,
            'photo_audit_status' => MemberProfile::PHOTO_AUDIT_STATUS_AUDITING
        ]);
    }

    /**
     * 修改用户头像
     * @param $userId
     * @param $avatar
     * @return bool
     * @throws Exception
     */
    public function modifyUserAvatar($userId, $avatar)
    {
        $member = parent::info(['user_id' => $userId]);
        if($member['realname_auth_status'] == 0) {
            throw new Exception('请先完成实名认证');
        }
        if($this->getUserService()->updateByPk([
            'id' => $userId,
            'auditing_avatar' => $avatar,
            'avatar_audit_status' => User::AVATAR_AUDIT_STATUS_AUDITING
        ])) {
            return true;
        }
        throw new Exception('修改失败');
    }

    public function onAuditUserAvatar($userId, $status)
    {
        $user = $this->getUserService()->getByPk($userId);
        $data = [
            'id' => $userId
        ];
        if($status == User::AVATAR_AUDIT_STATUS_APPROVED) {
            $data['avatar'] = $user['auditing_avatar'];
            $data['auditing_avatar'] = 0;
            $data['avatar_audit_status'] = 0;
        } else {
            $data['avatar_audit_status'] = $status;
        }
        return $this->getUserService()->updateByPk($data);
    }

    /**
     * 获取会员vip等级对应的权益
     * @param int $userId   --用户ID
     * @return array
     */
    public function getVipRightsByUserId($userId)
    {
        $site = config('site');
        $vipLevels = $site['vip_levels'];
        $memberProfile = $this->getByUserId($userId);
        $vipLevelItem = $vipLevels[$memberProfile['vip_level']];
        return $vipLevelItem['rights']['items'];
    }

    public function search(array $params, $page, $pageSize)
    {
        if (!class_exists('SphinxClient')) {
            require_once EXTEND_PATH . 'vm/org/SphinxClient.php';
        }

        $sphinx = (new Coreseek())->init();

        $kws = [];
        if(!empty($params['keywords'])) {
            $params['keywords'] = $sphinx->EscapeString($params['keywords']);
            $keywords = $sphinx->BuildKeywords($params['keywords'], 'marriage_seeking_member_profile', false);
            if (is_array($keywords)) {
                foreach ($keywords as $v) {
                    $kws[] = $v['normalized'];
                }
                $kws = array_unique($kws);
            }
        }

        // 设置字段的权重
        $sphinx->SetFieldWeights(['nick' => 50]);
        // 设置属性过滤
        if (isset($params['member_id'])) {
            $sphinx->SetFilter('member_id', is_array($params['member_id']) ? $params['member_id'] : [$params['member_id']]);
        }
        if (isset($params['user_id'])) {
            $sphinx->SetFilter('user_id', is_array($params['user_id']) ? $params['user_id'] : [$params['user_id']]);
        }
        if (isset($params['gender'])) {
            $sphinx->SetFilter('gender', is_array($params['gender']) ? $params['gender'] : [$params['gender']]);
        }
        if (isset($params['birthday_from']) && isset($params['birthday_to'])) {
            $sphinx->SetFilterRange('birthday', $params['birthday_from'], $params['birthday_to']);
        }
        if (isset($params['marriage_status'])) {
            $sphinx->SetFilter('marriage_status', [$params['marriage_status']]);
        }
        if (isset($params['job'])) {
            $sphinx->SetFilter('job', [$params['job']]);
        }
        if (isset($params['live_province'])) {
            $sphinx->SetFilter('live_province', [$params['live_province']]);
        }
        if (isset($params['live_city'])) {
            $sphinx->SetFilter('live_city', [$params['live_city']]);
        }
        if (isset($params['birth_province'])) {
            $sphinx->SetFilter('birth_province', [$params['birth_province']]);
        }
        if (isset($params['birth_city'])) {
            $sphinx->SetFilter('birth_city', [$params['birth_city']]);
        }
        if (isset($params['height_from']) && isset($params['height_to'])) {
            $sphinx->SetFilterRange('height', $params['height_from'], $params['height_to']);
        }
        if (isset($params['weight_from']) && isset($params['weight_to'])) {
            $sphinx->SetFilterRange('weight', $params['weight_from'], $params['weight_to']);
        }
        if (isset($params['education'])) {
            $sphinx->SetFilter('education', [$params['education']]);
        }
        if (isset($params['annual_income'])) {
            $sphinx->SetFilter('annual_income', [$params['annual_income']]);
        }
        if (isset($params['house_status'])) {
            $sphinx->SetFilter('house_status', [$params['house_status']]);
        }
        if (isset($params['house_location'])) {
            $sphinx->SetFilter('house_location', [$params['house_location']]);
        }
        if (isset($params['car_status'])) {
            $sphinx->SetFilter('car_status', [$params['car_status']]);
        }
        if (isset($params['kids'])) {
            $sphinx->SetFilter('kids', [$params['kids']]);
        }
        if (isset($params['nation'])) {
            $sphinx->SetFilter('nation', [$params['nation']]);
        }
        if (isset($params['blood_type'])) {
            $sphinx->SetFilter('blood_type', [$params['blood_type']]);
        }
        if (isset($params['faith'])) {
            $sphinx->SetFilter('faith', [$params['faith']]);
        }
        if (isset($params['smoke_status'])) {
            $sphinx->SetFilter('smoke_status', [$params['smoke_status']]);
        }
        if (isset($params['drink_status'])) {
            $sphinx->SetFilter('drink_status', [$params['drink_status']]);
        }
        if (isset($params['job_type'])) {
            $sphinx->SetFilter('job_type', [$params['job_type']]);
        }
        if (isset($params['distance_relationship_type'])) {
            $sphinx->SetFilter('distance_relationship_type', [$params['distance_relationship_type']]);
        }
        if (isset($params['child_type'])) {
            $sphinx->SetFilter('child_type', [$params['child_type']]);
        }
        if (isset($params['live_parents_type'])) {
            $sphinx->SetFilter('live_parents_type', [$params['live_parents_type']]);
        }
        if (isset($params['expect_age_from'])) {
            $sphinx->SetFilter('expect_age_from', [$params['expect_age_from']]);
        }
        if (isset($params['expect_age_to'])) {
            $sphinx->SetFilter('expect_age_to', [$params['expect_age_to']]);
        }
        if (isset($params['expect_height_from'])) {
            $sphinx->SetFilter('expect_height_from', [$params['expect_height_from']]);
        }
        if (isset($params['expect_height_to'])) {
            $sphinx->SetFilter('expect_height_to', [$params['expect_height_to']]);
        }
        if (isset($params['expect_weight_from'])) {
            $sphinx->SetFilter('expect_weight_from', [$params['expect_weight_from']]);
        }
        if (isset($params['expect_weight_to'])) {
            $sphinx->SetFilter('expect_weight_to', [$params['expect_weight_to']]);
        }
        if (isset($params['expect_location'])) {
            $sphinx->SetFilter('expect_location', [$params['expect_location']]);
        }
        if (isset($params['expect_marriage_status'])) {
            $sphinx->SetFilter('expect_marriage_status', [$params['expect_marriage_status']]);
        }
        if (isset($params['expect_house_status'])) {
            $sphinx->SetFilter('expect_house_status', [$params['expect_house_status']]);
        }
        if (isset($params['expect_car_status'])) {
            $sphinx->SetFilter('expect_car_status', [$params['expect_car_status']]);
        }
        if (isset($params['expect_kids_status'])) {
            $sphinx->SetFilter('expect_kids_status', [$params['expect_kids_status']]);
        }
        if (isset($params['expect_education_type'])) {
            $sphinx->SetFilter('expect_education_type', [$params['expect_education_type']]);
        }
        if (isset($params['expect_income_type'])) {
            $sphinx->SetFilter('expect_income_type', [$params['expect_income_type']]);
        }
        if (isset($params['expect_verify_status'])) {
            $sphinx->SetFilter('expect_verify_status', [$params['expect_verify_status']]);
        }
        if (isset($params['wxid_auth_status'])) {
            $sphinx->SetFilter('wxid_auth_status', [$params['wxid_auth_status']]);
        }
        if (isset($params['realname_auth_status'])) {
            $sphinx->SetFilter('realname_auth_status', [$params['realname_auth_status']]);
        }
        if (isset($params['marriage_auth_status'])) {
            $sphinx->SetFilter('marriage_auth_status', [$params['marriage_auth_status']]);
        }
        if (isset($params['education_auth_status'])) {
            $sphinx->SetFilter('education_auth_status', [$params['education_auth_status']]);
        }
        if (isset($params['house_auth_status'])) {
            $sphinx->SetFilter('house_auth_status', [$params['house_auth_status']]);
        }
        if (isset($params['car_auth_status'])) {
            $sphinx->SetFilter('car_auth_status', [$params['car_auth_status']]);
        }
        if (isset($params['marriage_seeking_status'])) {
            $sphinx->SetFilter('marriage_seeking_status', [$params['marriage_seeking_status']]);
        }
        if (isset($params['zodiac'])) {
            $sphinx->SetFilter('zodiac', [$params['zodiac']]);
        }
        if (isset($params['constellation'])) {
            $sphinx->SetFilter('constellation', [$params['constellation']]);
        }

        $sortBy = "@weight ASC, likes DESC, id DESC";
        $sphinx->SetSortMode(SPH_SORT_RELEVANCE, $sortBy);
        $sphinx->SetArrayResult(true);
        // 分页
        $sphinx->SetLimits(intval(ceil(($page - 1) * $pageSize)), $pageSize);
        // 查询
        if (!empty($kws)) {
            $query = '@(nick) (' . implode('|', $kws) . ')';
            $res = $sphinx->Query($query, "marriage_seeking_member_profile,delta_marriage_seeking_member_profile");
        } else {
            $res = $sphinx->Query('', "marriage_seeking_member_profile,delta_marriage_seeking_member_profile");
        }
        $sphinx = null;

        $total = 0;
        $ids = [];
        if ($res && empty($res['error']) && $res['total'] > 0) {
            if (is_array($res['matches'])) {
                foreach ($res['matches'] as $rss) {
                    $ids[] = $rss['id'];
                }
            }
            $total = $res['total'];
        }
        $dataList = [];
        if (!empty($ids)) {
            foreach ($ids as $v) {
                $dataList[] = $this->getByPk($v);
            }
        }

        $ret = [];
        $ret['total'] = $total;
        $ret['per_page'] = $pageSize;
        $ret['current_page'] = $page;
        $ret['last_page'] = ceil($ret['total'] / $ret['per_page']);
        $ret['data'] = $dataList;
        return $ret;
    }

    public function format(array $data)
    {
        $checked = [];
        $genders = MemberProfile::genders();
        if(isset($genders[$data['gender']])) {
            $data['gender_str'] = $genders[$data['gender']];
            $checked['gender'] = true;
        } else {
            $data['gender_str'] = '保密';
            $checked['gender'] = false;
        }

        if($data['birthday'] > 0) {
            $data['age'] = ceil((time() - $data['birthday']) / (3600*24*365));
            $checked['age'] = true;
        } else {
            $data['age'] = 0;
            $checked['age'] = false;
        }

        $marriageStatusList = MemberProfile::marriageStatus();
        if(isset($marriageStatusList[$data['marriage_status']])) {
            $data['marriage_status_str'] = $marriageStatusList[$data['marriage_status']];
            $checked['marriage_status'] = true;
        } else {
            $data['marriage_status_str'] = '未知';
            $checked['marriage_status'] = false;
        }

        $data['expect_marriage_status_str'] = [];
        if(!empty($data['expect_marriage_status'])) {
            $data['expect_marriage_status'] = explode(',', $data['expect_marriage_status']);
            foreach ($data['expect_marriage_status'] as $val) {
                $data['expect_marriage_status_str'][] = $marriageStatusList[$val];
            }
            $checked['expect_marriage_status'] = true;
        } else {
            $checked['expect_marriage_status'] = false;
            $data['expect_marriage_status'] = [];
        }

        $jobs = MemberProfile::jobs();
        if(isset($jobs[$data['job']])) {
            $data['job_str'] = $jobs[$data['job']];
            $checked['job'] = true;
        } else {
            $data['job_str'] = '未知';
            $checked['job'] = false;
        }

        if($data['live_city'] > 0) {
            $data['live_city_str'] = '';
            $regions = $this->regionLogic->parents($data['live_city']);
            foreach ($regions as $region) {
                $data['live_city_str'] .= $region['region_name'];
            }
            $checked['live_city'] = true;
        } else {
            $checked['live_city'] = false;
        }

        if($data['birth_city'] > 0) {
            $data['birth_city_str'] = '';
            $regions = $this->regionLogic->parents($data['birth_city']);
            foreach ($regions as $region) {
                $data['birth_city_str'] .= $region['region_name'];
            }
            $checked['birth_city'] = true;
        } else {
            $checked['birth_city'] = false;
        }

        $educationTypes = MemberProfile::educationTypes();
        if(isset($educationTypes[$data['education']])) {
            $data['education_str'] = $educationTypes[$data['education']];
            $checked['education'] = true;
        } else {
            $data['education_str'] = '未知';
            $checked['education'] = false;
        }

        $incomes = MemberProfile::incomes();
        if(isset($incomes[$data['annual_income']])) {
            $data['annual_income_str'] = $incomes[$data['annual_income']];
            $checked['annual_income'] = true;
        } else {
            $data['annual_income_str'] = '保密';
            $checked['annual_income'] = false;
        }

        $carStatusList = MemberProfile::carStatus();
        if(isset($carStatusList[$data['car_status']])) {
            $data['car_status_str'] = $carStatusList[$data['car_status']];
            $checked['car_status'] = true;
        } else {
            $data['car_status_str'] = '未知';
            $checked['car_status'] = false;
        }

        $houseStatusList = MemberProfile::houseStatus();
        if(isset($houseStatusList[$data['house_status']])) {
            $data['house_status_str'] = $houseStatusList[$data['house_status']];
            $checked['house_status'] = true;
        } else {
            $data['house_status_str'] = '未知';
            $checked['house_status'] = false;
        }

        $distanceRelationshipTypes = MemberProfile::distanceRelationshipTypes();
        if(isset($distanceRelationshipTypes[$data['distance_relationship_type']])) {
            $data['distance_relationship_type_str'] = $distanceRelationshipTypes[$data['distance_relationship_type']];
            $checked['distance_relationship_type'] = true;
        } else {
            $data['distance_relationship_type_str'] = '未知';
            $checked['distance_relationship_type'] = false;
        }

        $childTypes = MemberProfile::childTypes();
        if(isset($childTypes[$data['child_type']])) {
            $data['child_type_str'] = $childTypes[$data['child_type']];
            $checked['child_type'] = true;
        } else {
            $data['child_type_str'] = '未知';
            $checked['child_type'] = false;
        }

        $data['house_location_str'] = '';
        if($data['house_location'] > 0) {
            $regions = $this->regionLogic->parents($data['house_location']);
            foreach ($regions as $region) {
                $data['house_location_str'] .= $region['region_name'];
            }
            $checked['house_location'] = true;
        } else {
            $checked['house_location'] = false;
        }

        $liveParentsTypes = MemberProfile::liveParentsTypes();
        if(isset($liveParentsTypes[$data['live_parents_type']])) {
            $data['live_parents_type_str'] = $liveParentsTypes[$data['live_parents_type']];
            $checked['live_parents_type'] = true;
        } else {
            $data['live_parents_type_str'] = '未知';
            $checked['live_parents_type'] = false;
        }

        $kids = MemberProfile::kids();
        if(isset($kids[$data['kids']])) {
            $data['kids_str'] = $kids[$data['kids']];
            $checked['kids'] = true;
        } else {
            $data['kids_str'] = '未知';
            $checked['kids'] = false;
        }

        $nations = MemberProfile::nations();
        if(isset($nations[$data['nation']])) {
            $data['nation_str'] = $nations[$data['nation']];
            $checked['nation'] = true;
        } else {
            $data['nation_str'] = '未知';
            $checked['nation'] = false;
        }

        $bloodTypes = MemberProfile::bloodTypes();
        if(isset($bloodTypes[$data['blood_type']])) {
            $data['blood_type_str'] = $bloodTypes[$data['blood_type']];
            $checked['blood_type'] = true;
        } else {
            $data['blood_type_str'] = '未知';
            $checked['blood_type'] = false;
        }

        $faiths = MemberProfile::faiths();
        if(isset($faiths[$data['faith']])) {
            $data['faith_str'] = $faiths[$data['faith']];
            $checked['faith'] = true;
        } else {
            $data['faith_str'] = '未知';
            $checked['faith'] = false;
        }

        $smokes = MemberProfile::smokes();
        if(isset($smokes[$data['smoke_status']])) {
            $data['smoke_status_str'] = $smokes[$data['smoke_status']];
            $checked['smoke_status'] = true;
        } else {
            $data['smoke_status_str'] = '未知';
            $checked['smoke_status'] = false;
        }

        $drinks = MemberProfile::drinks();
        if(isset($drinks[$data['drink_status']])) {
            $data['drink_status_str'] = $drinks[$data['drink_status']];
            $checked['drink_status'] = true;
        } else {
            $data['drink_status_str'] = '未知';
            $checked['drink_status'] = false;
        }

        $jobTypes = MemberProfile::jobTypes();
        if(isset($jobTypes[$data['job_type']])) {
            $data['job_type_str'] = $jobTypes[$data['job_type']];
            $checked['job_type'] = true;
        } else {
            $data['job_type_str'] = '未知';
            $checked['job_type'] = false;
        }

        $data['constellation_str'] = '';
        if($data['constellation'] > -1) {
            $constellations = array_values(constellations());
            $data['constellation_str'] = isset($constellations[$data['constellation']]) ? $constellations[$data['constellation']] : '';
            $checked['constellation'] = true;
        } else {
            $checked['constellation'] = false;
        }

        $data['zodiac_str'] = '';
        if($data['zodiac'] > -1) {
            $zodiacs = zodiacs();
            $data['zodiac_str'] = isset($zodiacs[$data['zodiac']]) ? $zodiacs[$data['zodiac']] : '';
            $checked['zodiac'] = true;
        } else {
            $checked['zodiac'] = false;
        }

        $data['expect_location_str'] = '';
        if($data['expect_location'] > 0) {
            $regions = $this->regionLogic->parents($data['expect_location']);
            foreach ($regions as $region) {
                $data['expect_location_str'] .= $region['region_name'];
            }
            $checked['expect_location'] = true;
        } else {
            $checked['expect_location'] = false;
        }

        if(isset($houseStatusList[$data['expect_house_status']])) {
            $data['expect_house_status_str'] = $houseStatusList[$data['expect_house_status']];
            $checked['expect_house_status'] = true;
        } else {
            $data['expect_house_status_str'] = '未知';
            $checked['expect_house_status'] = false;
        }

        $data['expect_house_location_str'] = '';
        if($data['expect_house_location'] > 0) {
            $regions = $this->regionLogic->parents($data['expect_house_location']);
            foreach ($regions as $region) {
                $data['expect_house_location_str'] .= $region['region_name'];
            }
            $checked['expect_house_location'] = true;
        } else {
            $checked['expect_house_location'] = false;
        }

        if(isset($carStatusList[$data['expect_car_status']])) {
            $data['expect_car_status_str'] = $carStatusList[$data['expect_car_status']];
            $checked['expect_car_status'] = true;
        } else {
            $data['expect_car_status_str'] = '未知';
            $checked['expect_car_status'] = false;
        }

        if(isset($kids[$data['expect_kids_status']])) {
            $data['expect_kids_status_str'] = $kids[$data['expect_kids_status']];
            $checked['expect_kids_status'] = true;
        } else {
            $data['expect_kids_status_str'] = '未知';
            $checked['expect_kids_status'] = false;
        }

        if(isset($educationTypes[$data['expect_education_type']])) {
            $data['expect_education_type_str'] = $educationTypes[$data['expect_education_type']];
            $checked['expect_education_type'] = true;
        } else {
            $data['expect_education_type_str'] = '未知';
            $checked['expect_education_type'] = false;
        }

        if(isset($incomes[$data['expect_income_type']])) {
            $data['expect_income_type_str'] = $incomes[$data['expect_income_type']];
            $checked['expect_income_type'] = true;
        } else {
            $data['expect_income_type_str'] = '保密';
            $checked['expect_income_type'] = false;
        }

        if($data['expect_verify_status'] == 0) {
            $data['expect_verify_status_str'] = '不限';
        } else if($data['expect_verify_status'] == 1) {
            $data['expect_verify_status_str'] = '已认证';
        }

        $data['vip_level_str'] = '普通会员';
        if($data['vip_level'] > 0 && $data['vip_level_end_time'] < time()) {
            $data['vip_level'] = 0;
            $data['vip_level_end_time'] = 0;
        } else if($data['vip_level'] > 0 && $data['vip_level_end_time'] > time()) {
            $site = config('site');
            $vipLevels = $site['vip_levels'];
            foreach ($vipLevels as $item) {
                if($data['vip_level'] == $item['value']) {
                    $data['vip_level_str'] = $item['name'];
                    break;
                }
            }
        }

        $data['photo_url'] = '';
        if(!empty($data['photo'])) {
            $checked['photo'] = true;
        } else {
            $checked['photo'] = false;
        }
        if(!empty($data['photo']) && is_numeric($data['photo'])) {
            $file = $this->getFileLogic()->file($data['photo']);
            if($file) {
                $data['photo_url'] = $file['url'];
            }
        } else {
            $data['photo_url'] = $data['photo'];
        }

        if($data['auditing_photo'] > 0) {
            $file = $this->getFileLogic()->file($data['auditing_photo']);
            if($file) {
                $data['auditing_photo_url'] = $file['url'];
            }
        } else {
            $data['auditing_photo_url'] = '';
        }

        if($data['marriage_seeking_status'] == 1) {
            $data['marriage_seeking_status_str'] = '征婚中';
        } else {
            $data['marriage_seeking_status_str'] = '隐藏资料';
        }

        // 资料完善度
        $checkedCount = 0;
        foreach ($checked as $val) {
            if($val) {
                $checkedCount++;
            }
        }
        $data['perfection_degree'] = ceil(($checkedCount / count($checked)) * 100);
        return $data;
    }

    public function onViewWxid($userId, $memberId)
    {
        $rights = $this->getVipRightsByUserId($userId);
        if(!$rights['unlock_wxid_enable']) {
            throw new Exception('您当前无权限查看会员微信号');
        }
        if($rights['unlock_wxid_amount_per_day'] != -1
            && $this->getMemberRechargeRecordService()->count([
                'user_id' => $userId,
                'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_WXID,
                'min_dateline' => strtotime(date('Ymd') . ' 00:00:00'),
                'max_dateline' => strtotime(date('Ymd') . ' 23:59:59'),
            ]) >= $rights['unlock_wxid_amount_per_day']) {
            throw new Exception('您当前每天可查看'.$rights['unlock_wxid_amount_per_day'].'个微信号');
        }

        $member = $this->getByPk($memberId);
        if(empty($member)) {
            throw new Exception('该会员不存在');
        }
        $memberUid = $member['user_id'];
        try {
            if(!$this->getMemberRechargeRecordService()->info([
                'user_id' => $userId,
                'iid' => $memberId,
                'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_WXID
            ])) {
                $this->decrease('wxid_view_amount', [
                    'id' => $memberId,
                    'wxid_view_amount' => ['>', 0]
                ]);
                $this->getMemberRechargeRecordService()->create([
                    'user_id' => $userId,
                    'iid' => $memberId,
                    'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_WXID
                ]);
            }
        } catch (Exception $e) {
            throw new Exception('次数不足', ERROR_SHORT_VIEW_WXID_AMOUNT);
        }
        if($member['wxid_audit_enable'] == 0) { // 不需要对方审核
            return [
                'code' => 0,
                'wxid' => $member['wxid']
            ];
        } else {    // 需要对方审核
            if($this->getMemberProfileExchangeApplyService()->info([
                'apply_uid' => $userId,
                'member_uid' => $memberUid,
                'type' => MemberProfileExchangeApply::TYPE_VIEW_WXID,
                'status' => MemberProfileExchangeApply::STATUS_PASS
            ])) {
                return [
                    'code' => 0,
                    'wxid' => $member['wxid']
                ];
            }

            $applyId = $this->getMemberProfileExchangeApplyService()->insert([
                'apply_uid' => $userId,
                'member_uid' => $memberUid,
                'type' => MemberProfileExchangeApply::TYPE_VIEW_WXID,
                'status' => MemberProfileExchangeApply::STATUS_AUDITING,
                'apply_time' => time()
            ], true);

            // 发送通知
            $user = $this->getUserService()->getByPk($userId);
            $systemNoticeId = $this->getSystemNoticeService()->create([
                'title' => '微信号查看请求',
                'content' => '用户【'.$user['nick'].'】请求查看你的微信号，请处理该请求。',
                'type' => SystemNotice::TYPE_SINGLE,
                'status' => SystemNotice::STATUS_PULLED,
                'recipient_id' => $memberUid,
                'manager_id' => 0,
                'url' => json_encode([
                    'weapp' => '/pages/my/member_profile_exchange_apply/list',
                    'web' => '/my_member_profile_exchange_apply_list',
                    'app' => '/my/member_profile_exchange_apply/list'
                ])
            ]);
            $this->getUserSystemNoticeService()->create([
                'system_notice_id' => $systemNoticeId,
                'recipient_id' => $memberUid,
                'status' => UserSystemNotice::STATUS_WAIT_READ,
                'pull_time' => time()
            ]);

            // 给被申请人发送公众号通知
            try {
                if($this->getUserPlatformService()->checkUserSubscribedMpAccount($memberUid)) {
                    $userPlatform = $this->getUserPlatformService()->info([
                        'user_id' => $memberUid,
                        'platform' => UserPlatform::PLATFORM_WX_MP
                    ]);
                    if($userPlatform) {
                        $openid = $userPlatform['open_id'];
                        $wechatConfig = config('wechat');
                        $msgTemplateId = $wechatConfig['mp_msg_templates']['service_apply_notice'];
                        $msgData = [
                            'first' => [
                                'value' => '微信号查看请求'
                            ],
                            'keyword1' => [
                                'value' => $user['nick']
                            ],
                            'keyword2' => [
                                'value' => date('Y-m-d H:i:s')
                            ],
                            'keyword3' => [
                                'value' => '待处理'
                            ],
                            'remark' => [
                                'value' => '请点击链接处理该请求。'
                            ]
                        ];
                        $url = $this->getSiteConfigService()->getValueByCode('mp_site') . '/my_member_profile_exchange_apply_list';
                        $miniprogram = null;

                        $queueConfig = config('queue');
                        $queueHandler = QueueFactory::instance();
                        $queueHandler->set($queueConfig['queues']['mp_msg'], [
                            'openid' => $openid,
                            'template_id' => $msgTemplateId,
                            'data' => $msgData,
                            'url' => $url,
                            'miniprogram' => $miniprogram
                        ]);
                    }
                }
            } catch (\Exception $e) {
                $log = 'FILE:' . $e->getFile() . "\r\n" . 'LINE:' . $e->getLine(). "\r\n" . 'MSG:' . $e->getMessage();
                Log::error($log);
            }

            return [
                'code' => ERROR_VIEW_WXID_WAIT_AUDIT,
                'wxid' => ''
            ];
        }
    }

    public function onUnlockPhoneNumber($userId, $memberId)
    {
        $rights = $this->getVipRightsByUserId($userId);
        if(!$rights['unlock_phone_enable']) {
            throw new Exception('您当前无权限查看会员微信号');
        }
        if($rights['unlock_phone_amount_per_day'] != -1
            && $this->getMemberRechargeRecordService()->count([
                'user_id' => $userId,
                'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_PHONE,
                'min_dateline' => strtotime(date('Ymd') . ' 00:00:00'),
                'max_dateline' => strtotime(date('Ymd') . ' 23:59:59'),
            ]) >= $rights['unlock_phone_amount_per_day']) {
            throw new Exception('您当前每天可查看'.$rights['unlock_phone_amount_per_day'].'个手机号');
        }

        $member = $this->getByPk($memberId);
        if(empty($member)) {
            throw new Exception('该会员不存在');
        }
        $memberUid = $member['user_id'];
        $phone = $this->getUserService()->getMobilePhone($member['user_id']);
        if($member['hidden_mobile_enable'] == 1 || stripos($phone, "000") === 0) {
            throw new Exception('该用户禁止查看手机号');
        }
        try {
            if(!$this->getMemberRechargeRecordService()->info([
                'user_id' => $userId,
                'iid' => $memberId,
                'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_PHONE
            ])) {
                $this->decrease('phone_view_amount', [
                    'id' => $memberId,
                    'phone_view_amount' => ['>', 0]
                ]);
                $this->getMemberRechargeRecordService()->create([
                    'user_id' => $userId,
                    'iid' => $memberId,
                    'iid_type' => MemberRechargeRecord::IID_TYPE_UNLOCK_MEMBER_PHONE
                ]);
            }
        } catch (Exception $e) {
            throw new Exception('次数不足', ERROR_SHORT_VIEW_PHONE_NUMBER);
        }

        if($member['phone_audit_enable'] == 0) {    // 不需要对方审核
            return [
                'code' => 0,
                'phone' => $phone
            ];
        } else {    // 需要对方审核
            if($this->getMemberProfileExchangeApplyService()->info([
                'apply_uid' => $userId,
                'member_uid' => $memberUid,
                'type' => MemberProfileExchangeApply::TYPE_UNLOCK_PHONE,
                'status' => MemberProfileExchangeApply::STATUS_PASS
            ])) {
                return [
                    'code' => 0,
                    'phone' => $phone
                ];
            }

            $applyId = $this->getMemberProfileExchangeApplyService()->insert([
                'apply_uid' => $userId,
                'member_uid' => $memberUid,
                'type' => MemberProfileExchangeApply::TYPE_UNLOCK_PHONE,
                'status' => MemberProfileExchangeApply::STATUS_AUDITING,
                'apply_time' => time()
            ], true);

            // 发送通知
            $user = $this->getUserService()->getByPk($userId);
            $systemNoticeId = $this->getSystemNoticeService()->create([
                'title' => '手机号查看请求',
                'content' => '用户【'.$user['nick'].'】请求查看你的手机号，请处理该请求。',
                'type' => SystemNotice::TYPE_SINGLE,
                'status' => SystemNotice::STATUS_PULLED,
                'recipient_id' => $memberUid,
                'manager_id' => 0,
                'url' => json_encode([
                    'weapp' => '/pages/my/member_profile_exchange_apply/list',
                    'web' => '/my_member_profile_exchange_apply_list',
                    'app' => '/my/member_profile_exchange_apply/list'
                ])
            ]);
            $this->getUserSystemNoticeService()->create([
                'system_notice_id' => $systemNoticeId,
                'recipient_id' => $memberUid,
                'status' => UserSystemNotice::STATUS_WAIT_READ,
                'pull_time' => time()
            ]);

            // 给被申请人发送公众号通知
            try {
                if($this->getUserPlatformService()->checkUserSubscribedMpAccount($memberUid)) {
                    $userPlatform = $this->getUserPlatformService()->info([
                        'user_id' => $memberUid,
                        'platform' => UserPlatform::PLATFORM_WX_MP
                    ]);
                    if($userPlatform) {
                        $openid = $userPlatform['open_id'];
                        $wechatConfig = config('wechat');
                        $msgTemplateId = $wechatConfig['mp_msg_templates']['service_apply_notice'];
                        $msgData = [
                            'first' => [
                                'value' => '手机号查看请求'
                            ],
                            'keyword1' => [
                                'value' => $user['nick']
                            ],
                            'keyword2' => [
                                'value' => date('Y-m-d H:i:s')
                            ],
                            'keyword3' => [
                                'value' => '待处理'
                            ],
                            'remark' => [
                                'value' => '请点击链接处理该请求。'
                            ]
                        ];
                        $url = $this->getSiteConfigService()->getValueByCode('mp_site') . '/my_member_profile_exchange_apply_list';
                        $miniprogram = null;

                        $queueConfig = config('queue');
                        $queueHandler = QueueFactory::instance();
                        $queueHandler->set($queueConfig['queues']['mp_msg'], [
                            'openid' => $openid,
                            'template_id' => $msgTemplateId,
                            'data' => $msgData,
                            'url' => $url,
                            'miniprogram' => $miniprogram
                        ]);
                    }
                }
            } catch (\Exception $e) {
                $log = 'FILE:' . $e->getFile() . "\r\n" . 'LINE:' . $e->getLine(). "\r\n" . 'MSG:' . $e->getMessage();
                Log::error($log);
            }

            return [
                'code' => ERROR_VIEW_PHONE_WAIT_AUDIT,
                'phone' => ''
            ];
        }
    }

    public function getLiveRoomBgImage($memberId)
    {
        $hash = md5($memberId);
        $path = 'uploads/live_room_bg/' . $hash{0} . '/' . $hash{1} . '/' . $memberId . '.jpg';
        $url = request()->scheme() . '://' . request()->host() . '/' . getContextPath() . $path;
        if (is_file(WWW_PATH . $path)) {
            return $url;
        }
        if (!is_dir(dirname(WWW_PATH . $path))) {
            makeDir(dirname(WWW_PATH . $path));
        }
        $tempDir = WWW_PATH . 'uploads/temp/' . date('Ymd') . '/';
        if(!is_dir($tempDir)) {
            makeDir($tempDir);
        }

        $member = $this->getByPk($memberId);
        if(empty($member)) {
            throw new Exception('会员不存在');
        }
        $member = $this->format($member);
        $user = $this->getUserService()->getByPk($member['user_id']);

        $avatar = $member['photo_url'];
        if(empty($avatar)) {
            $avatar = $user['avatar_url'];
            if(empty($avatar)) {
                if($member['gender'] == 0 || $member['gender'] == MemberProfile::GENDER_MALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_male.png';
                } else if($member['gender'] == MemberProfile::GENDER_FEMALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_female.png';
                }
            }
        }

        if(stripos($avatar, 'http') !== false) {
            $fname = grabRemoteFile($avatar, $tempDir);
            $avatar = $tempDir . $fname;
        }

        $images = [];
        $images[] = [
            'url' => $avatar,       //图片资源路径
            'left' => 384,
            'top' => 646,
            'stream' => 0,             //图片资源是否是字符串图像流
            'right' => 0,
            'bottom' => 0,
            'width' => 413,
            'height' => 417,
            'opacity' => 100
        ];

        $texts = [];
        $mediumFont = DOC_PATH . 'data/font/Alibaba-PuHuiTi-Medium.otf';

        // 昵称
        $nick = $user['nick'];
        $fontSize = 50;
        $nickTextPos = imagettfbbox($fontSize, 0, $mediumFont, $nick);
        $nickTextLineHeight = $nickTextPos[1] - $nickTextPos[7];
        $texts[] = [
            'text' => $nick,
            'left' => 384 + (413 - $nickTextPos[2]) / 2,
            'top' => 646 + 417 + 10 + $nickTextLineHeight,
            'fontPath' => $mediumFont,     //字体文件
            'fontSize' => $fontSize,   //字号
            'fontColor' => '255,255,255',       //字体颜色
            'angle' => 0
        ];

        $fontSize = 50;
        $baseTop = 600;
        $baseLeft = 830;
        // 年龄
        if($member['birthday'] > 0) {
            $strAge = '年龄：';
            $strAge .= $member['age'] .'岁 ';
            $ageTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strAge);
            $ageTextLineHeight = $ageTextPos[1] - $ageTextPos[7];
            $ageTextTop = $baseTop + 10 + $ageTextLineHeight;
            $texts[] = [
                'text' => $strAge,
                'left' => $baseLeft,
                'top' => $ageTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $ageTextTop;
        }
        // 身高
        if($member['height'] > 0) {
            $strHeight = '身高：';
            $strHeight .= $member['height'];
            $heightTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strHeight);
            $heightTextLineHeight = $heightTextPos[1] - $heightTextPos[7];
            $heightTextTop = $baseTop + 20 + $heightTextLineHeight;
            $texts[] = [
                'text' => $strHeight,
                'left' => $baseLeft,
                'top' => $heightTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $heightTextTop;
        }
        // 学历
        if($member['education'] > 0) {
            $strEducation = '学历：';
            $strEducation .= $member['education_str'];
            $educationTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strEducation);
            $educationTextLineHeight = $educationTextPos[1] - $educationTextPos[7];
            $educationTextTop = $baseTop + 20 + $educationTextLineHeight;
            $texts[] = [
                'text' => $strEducation,
                'left' => $baseLeft,
                'top' => $educationTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $educationTextTop;
        }
        // 婚况
        if($member['marriage_status'] > 0) {
            $strMarriage = '婚况：';
            $strMarriage .= $member['marriage_status_str'];
            $marriageTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strMarriage);
            $marriageTextLineHeight = $marriageTextPos[1] - $marriageTextPos[7];
            $marriageTextTop = $baseTop + 20 + $marriageTextLineHeight;
            $texts[] = [
                'text' => $strMarriage,
                'left' => $baseLeft,
                'top' => $marriageTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $marriageTextTop;
        }
        // 职业
        if($member['job'] > 0) {
            $strJob = '职业：';
            $strJob .= $member['job_str'];
            $jobTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strJob);
            $jobTextLineHeight = $jobTextPos[1] - $jobTextPos[7];
            $jobTextTop = $baseTop + 20 + $jobTextLineHeight;
            $texts[] = [
                'text' => $strJob,
                'left' => $baseLeft,
                'top' => $jobTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $jobTextTop;
        }
        // 城市
        if($member['live_city'] > 0) {
            $strLiveCity = '城市：';
            $strLiveCity .= $member['live_city_str'];
            $liveCityTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strLiveCity);
            $liveCityTextLineHeight = $liveCityTextPos[1] - $liveCityTextPos[7];
            $liveCityTextTop = $baseTop + 20 + $liveCityTextLineHeight;
            $texts[] = [
                'text' => $strLiveCity,
                'left' => $baseLeft,
                'top' => $liveCityTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $liveCityTextTop;
        }
        // 收入
        if($member['annual_income'] > 0) {
            $strAnnualIncome = '收入：';
            $strAnnualIncome .= $member['annual_income_str'];
            $annualIncomeTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strAnnualIncome);
            $annualIncomeTextLineHeight = $annualIncomeTextPos[1] - $annualIncomeTextPos[7];
            $annualIncomeTextTop = $baseTop + 20 + $annualIncomeTextLineHeight;
            $texts[] = [
                'text' => $strAnnualIncome,
                'left' => $baseLeft,
                'top' => $annualIncomeTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $annualIncomeTextTop;
        }

        // 择偶要求
        $baseTop = 1430;
        $baseLeft = 335;
        $fontSize = 60;

        // 年龄、身高
        if($member['expect_age_from'] > 0 || $member['expect_age_to'] > 0
            || $member['expect_height_from'] > 0 || $member['expect_height_to'] > 0) {
            $strExpectAgeHeight = '';
            if($member['expect_age_from'] > 0 || $member['expect_age_to'] > 0) {
                $strExpectAgeHeight .= '年龄：';
                if($member['expect_age_from'] > 0 && $member['expect_age_to'] > 0) {
                    $strExpectAgeHeight .= $member['expect_age_from'] . '-' . $member['expect_age_to'];
                } else if($member['expect_age_from'] == 0 && $member['expect_age_to'] > 0) {
                    $strExpectAgeHeight .= $member['expect_age_to'] . '以下';
                } else if($member['expect_age_from'] > 0 && $member['expect_age_to'] == 0) {
                    $strExpectAgeHeight .= $member['expect_age_from'] . '以上';
                }
            }

            if($member['expect_height_from'] > 0 || $member['expect_height_to'] > 0) {
                if($member['expect_age_from'] > 0 || $member['expect_age_to'] > 0) {
                    $strExpectAgeHeight .= ' / ';
                }
                $strExpectAgeHeight .= '身高：';
                if($member['expect_height_from'] > 0 && $member['expect_height_to'] > 0) {
                    $strExpectAgeHeight .= $member['expect_height_from'] . '-' . $member['expect_height_to'];
                } else if($member['expect_height_from'] == 0 && $member['expect_height_to'] > 0) {
                    $strExpectAgeHeight .= $member['expect_height_to'] . '以下';
                } else if($member['expect_height_from'] > 0 && $member['expect_height_to'] == 0) {
                    $strExpectAgeHeight .= $member['expect_height_from'] . '以上';
                }
            }

            $expectAgeHeightTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectAgeHeight);
            $expectAgeHeightTextLineHeight = $expectAgeHeightTextPos[1] - $expectAgeHeightTextPos[7];
            $expectAgeHeightTextTop = $baseTop + 60 + $expectAgeHeightTextLineHeight;
            $texts[] = [
                'text' => $strExpectAgeHeight,
                'left' => $baseLeft,
                'top' => $expectAgeHeightTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $expectAgeHeightTextTop;
        }

        // 学历 / 收入
        if($member['expect_education_type'] > 0 || $member['expect_income_type'] > 0) {
            $strExpectEducation = '';
            if($member['expect_education_type'] > 0) {
                $strExpectEducation .= '学历：' . $member['expect_education_type_str'];
            }
            if($member['expect_income_type'] > 0) {
                if($member['expect_education_type'] > 0) {
                    $strExpectEducation .= ' / ';
                }
                $strExpectEducation .= '收入：' . $member['expect_income_type_str'];
            }
            $expectEducationTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectEducation);
            $expectEducationTextLineHeight = $expectEducationTextPos[1] - $expectEducationTextPos[7];
            $expectEducationTextTop = $baseTop + 20 + $expectEducationTextLineHeight;
            $texts[] = [
                'text' => $strExpectEducation,
                'left' => $baseLeft,
                'top' => $expectEducationTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $expectEducationTextTop;
        }

        // 收入
//        if($member['expect_income_type'] > 0) {
//            $strExpectIncome = '收入：' . $member['expect_income_type_str'];
//            $expectIncomeTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectIncome);
//            $expectIncomeTextLineHeight = $expectIncomeTextPos[1] - $expectIncomeTextPos[7];
//            $expectIncomeTextTop = $baseTop + 20 + $expectIncomeTextLineHeight;
//            $texts[] = [
//                'text' => $strExpectIncome,
//                'left' => $baseLeft,
//                'top' => $expectIncomeTextTop,
//                'fontPath' => $mediumFont,     //字体文件
//                'fontSize' => $fontSize,   //字号
//                'fontColor' => '255,255,255',       //字体颜色
//                'angle' => 0
//            ];
//            $baseTop = $expectIncomeTextTop;
//        }

        // 婚况
        if(!empty($member['expect_marriage_status'])) {
            $strExpectMarriage = '婚况：' . implode('、', $member['expect_marriage_status_str']);
            $expectMarriageTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectMarriage);
            $expectMarriageTextLineHeight = $expectMarriageTextPos[1] - $expectMarriageTextPos[7];
            $expectMarriageTextTop = $baseTop + 20 + $expectMarriageTextLineHeight;
            $texts[] = [
                'text' => $strExpectMarriage,
                'left' => $baseLeft,
                'top' => $expectMarriageTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $expectMarriageTextTop;
        }

        // 房产
        if($member['expect_house_status'] == 20) {
            $strExpectHouse = '房产：' . $member['expect_house_status_str'];
            if($member['expect_house_location'] > 0) {
                $strExpectHouse .= '('.$member['expect_house_location_str'].')';
            }
            $expectHouseTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectHouse);
            $expectHouseTextLineHeight = $expectHouseTextPos[1] - $expectHouseTextPos[7];
            $expectHouseTextTop = $baseTop + 20 + $expectHouseTextLineHeight;
            $texts[] = [
                'text' => $strExpectHouse,
                'left' => $baseLeft,
                'top' => $expectHouseTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $expectHouseTextTop;
        }

        // 车子
        if($member['expect_car_status'] == 20) {
            $strExpectCar = '汽车：' . $member['expect_car_status_str'];
            $expectCarTextPos = imagettfbbox($fontSize, 0, $mediumFont, $strExpectCar);
            $expectCarTextLineHeight = $expectCarTextPos[1] - $expectCarTextPos[7];
            $expectCarTextTop = $baseTop + 20 + $expectCarTextLineHeight;
            $texts[] = [
                'text' => $strExpectCar,
                'left' => $baseLeft,
                'top' => $expectCarTextTop,
                'fontPath' => $mediumFont,     //字体文件
                'fontSize' => $fontSize,   //字号
                'fontColor' => '255,255,255',       //字体颜色
                'angle' => 0
            ];
            $baseTop = $expectCarTextTop;
        }

        $config = [
            'image' => $images,
            'text' => $texts,
            'background' => DOC_PATH . 'data/images/liveroom_bg.jpg'
        ];
        createPoster($config, WWW_PATH . $path);
        return $url;
    }

    public function getSharePoster($memberId, $fromuid)
    {
        $hash = md5($memberId . $fromuid);
        $path = 'uploads/share_poster/member/' . $hash{0} . '/' . $hash{1} . '/' . $memberId . '/'.$fromuid.'.jpg';
        $url = request()->scheme() . '://' . request()->host() . '/' . getContextPath() . $path;
        if (is_file(WWW_PATH . $path)) {
            return $url;
        }
        if (!is_dir(dirname(WWW_PATH . $path))) {
            makeDir(dirname(WWW_PATH . $path));
        }
        $tempDir = WWW_PATH . 'uploads/temp/' . date('Ymd') . '/';
        if(!is_dir($tempDir)) {
            makeDir($tempDir);
        }

        $member = $this->getByPk($memberId);
        if(empty($member)) {
            throw new Exception('会员不存在');
        }
        $member = $this->format($member);
        $user = $this->getUserService()->getByPk($member['user_id']);

        $avatar = $member['photo_url'];
        if(empty($avatar)) {
            $avatar = $user['avatar_url'];
            if(empty($avatar)) {
                if($member['gender'] == 0 || $member['gender'] == MemberProfile::GENDER_MALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_male.png';
                } else if($member['gender'] == MemberProfile::GENDER_FEMALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_female.png';
                }
            }
        }

        if(stripos($avatar, 'http') !== false) {
            $fname = grabRemoteFile($avatar, $tempDir);
            $avatar = $tempDir . $fname;
        }
//        $roundAvatar = $tempDir . time() . '_' . rand_string(6) . '.png';
//        $avatarData = yuanImg(file_get_contents($avatar));
//        file_put_contents($roundAvatar, $avatarData);

        $fontfile = DOC_PATH . 'data/font/Alibaba-PuHuiTi-Regular.otf';
        $textColor = '123,104,238';

        $texts = [];

        $nick = $user['nick'];
        $fontSize = 18;
        $nickTextPos = imagettfbbox($fontSize, 0, $fontfile, $nick);
        $nickTextLineHeight = $nickTextPos[1] - $nickTextPos[7];
        $texts[] = [
            'text' => $nick,
            'left' => (780 - $nickTextPos[2]) / 2,
            'top' => 380 + 10 + $nickTextLineHeight,
            'fontPath' => $fontfile,     //字体文件
            'fontSize' => $fontSize,   //字号
            'fontColor' => '0,0,0',       //字体颜色
            'angle' => 0
        ];

        $str1 = '';
        if($member['live_city'] > 0) {
            $str1 .= '现居' . $member['live_city_str'] . ' ';
        }
        if($member['birthday'] > 0) {
            $str1 .= $member['age'] .'岁 ';
        }
        if($member['marriage_status'] > 0) {
            $str1 .= $member['marriage_status_str'] . ' ';
        }
        if($member['job'] > 0) {
            $str1 .= $member['job_str'] . ' ';
        }
        if($member['education']) {
            $str1 .= $member['education_str'] . ' ';
        }

        $str1 = trim($str1);
        if(!empty($str1)) {
            $fontSize1 = 13;
            $str1Pos = imagettfbbox($fontSize1, 0, $fontfile, $str1);
            $str1LineHeight = $str1Pos[1] - $str1Pos[7];
            $texts[] = [
                'text' => $str1,
                'left' => (780 - $str1Pos[2]) / 2,
                'top' => 430 + 10 + $nickTextLineHeight + 10 + $str1LineHeight,
                'fontPath' => $fontfile,     //字体文件
                'fontSize' => $fontSize1,   //字号
                'fontColor' => $textColor,       //字体颜色
                'angle' => 0
            ];
        }

        $str2 = '';
        if($member['annual_income']) {
            $str2 .= '年薪' . $member['annual_income_str'] . ' ';
        }
        if($member['house_status'] > 0) {
            $str2 .= $member['house_status_str'] . ' ';
        }
        if($member['car_status'] > 0) {
            $str2 .= $member['car_status_str'] . ' ';
        }
        $str2 = trim($str2);
        if(!empty($str2)) {
            $fontSize2 = 13;
            $str2Pos = imagettfbbox($fontSize2, 0, $fontfile, $str2);
            $str2LineHeight = $str2Pos[1] - $str2Pos[7];
            $texts[] = [
                'text' => $str2,
                'left' => (780 - $str2Pos[2]) / 2,
                'top' => 430 + 10 + $nickTextLineHeight + (!empty($str1) ? (10 + $str1LineHeight + 10) : 10) + $str2LineHeight,
                'fontPath' => $fontfile,     //字体文件
                'fontSize' => $fontSize2,   //字号
                'fontColor' => $textColor,       //字体颜色
                'angle' => 0
            ];
        }

        $fontfile2 = DOC_PATH . 'data/font/Alibaba-PuHuiTi-Light.otf';

        $str3 = '"爱具体的人，不要爱抽象的人，';
        $fontSize3 = 18;
        $str3Pos = imagettfbbox($fontSize3, 0, $fontfile2, $str3);
        $str3LineHeight = $str3Pos[1] - $str3Pos[7];
        $texts[] = [
            'text' => $str3,
            'left' => (780 - $str3Pos[2]) / 2,
            'top' => 600,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize3,   //字号
            'fontColor' => '128,128,128',       //字体颜色
            'angle' => 0
        ];

        $str4 = '要爱生活，不要爱生活的意义"';
        $fontSize4 = 18;
        $str4Pos = imagettfbbox($fontSize4, 0, $fontfile2, $str4);
        $str4LineHeight = $str4Pos[1] - $str4Pos[7];
        $texts[] = [
            'text' => $str4,
            'left' => (780 - $str4Pos[2]) / 2,
            'top' => 600 + 10 + $str3LineHeight,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize4,   //字号
            'fontColor' => '128,128,128',       //字体颜色
            'angle' => 0
        ];

        $str5 = '长按二维码 开启缘分之门';
        $fontSize5 = 13;
        $str5Pos = imagettfbbox($fontSize5, 0, $fontfile2, $str5);
        $str5LineHeight = $str5Pos[1] - $str5Pos[7];
        $texts[] = [
            'text' => $str5,
            'left' => (780 - $str5Pos[2]) / 2,
            'top' => 935,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize5,   //字号
            'fontColor' => '0,0,0',       //字体颜色
            'angle' => 0
        ];

        $images = [];
        $images[] = [
            'url' => $avatar,       //图片资源路径
            'left' => 310,
            'top' => 220,
            'stream' => 0,             //图片资源是否是字符串图像流
            'right' => 0,
            'bottom' => 0,
            'width' => 160,
            'height' => 160,
            'opacity' => 100
        ];

        // 生成二维码
        $mpSite = $this->getSiteConfigService()->getValueByCode('mp_site');
        require_once EXTEND_PATH . 'vm/org/phpqrcode.php';
        $qrUrl = $mpSite . '/member_profile?id='.$memberId.'&replace=1&fromuid=' . $fromuid;
        $qrFile = $tempDir . 'qrcode/' . time() . '_' . rand_string(6) . '.png';
        if(!is_dir(dirname($qrFile))) {
            makeDir(dirname($qrFile));
        }
        \QRcode::png($qrUrl, $qrFile);
        $images[] = [
            'url' => $qrFile,       //图片资源路径
            'left' => 310,
            'top' => 760,
            'stream' => 0,             //图片资源是否是字符串图像流
            'right' => 0,
            'bottom' => 0,
            'width' => 160,
            'height' => 160,
            'opacity' => 100
        ];

        $config = [
            'image' => $images,
            'text' => $texts,
            'background' => DOC_PATH . 'data/images/share_poster_1.jpg'
        ];
        createPoster($config, WWW_PATH . $path);
        return $url;
    }

    public function getMySharePoster($userId)
    {
        $hash = md5($userId);
        $path = 'uploads/share_poster/my/' . $hash{0} . '/' . $hash{1} . '/' . $userId . '.jpg';
        $url = request()->scheme() . '://' . request()->host() . '/' . getContextPath() . $path;
        if (is_file(WWW_PATH . $path)) {
            return $url;
        }
        if (!is_dir(dirname(WWW_PATH . $path))) {
            makeDir(dirname(WWW_PATH . $path));
        }
        $tempDir = WWW_PATH . 'uploads/temp/' . date('Ymd') . '/';
        if (!is_dir($tempDir)) {
            makeDir($tempDir);
        }
        $member = $this->getByUserId($userId);
        if(empty($member)) {
            throw new Exception('会员不存在');
        }
        $member = $this->format($member);
        $user = $this->getUserService()->getByPk($userId);

        $avatar = $member['photo_url'];
        if(empty($avatar)) {
            $avatar = $user['avatar_url'];
            if(empty($avatar)) {
                if($member['gender'] == 0 || $member['gender'] == MemberProfile::GENDER_MALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_male.png';
                } else if($member['gender'] == MemberProfile::GENDER_FEMALE) {
                    $avatar = DOC_PATH . 'data/images/avatar_female.png';
                }
            }
        }

        if(stripos($avatar, 'http') !== false) {
            $fname = grabRemoteFile($avatar, $tempDir);
            $avatar = $tempDir . $fname;
        }
//        $roundAvatar = $tempDir . time() . '_' . rand_string(6) . '.png';
//        $avatarData = yuanImg(file_get_contents($avatar));
//        file_put_contents($roundAvatar, $avatarData);

        $fontfile = DOC_PATH . 'data/font/Alibaba-PuHuiTi-Regular.otf';
        $textColor = '123,104,238';

        $texts = [];
        $images = [];

        $images[] = [
            'url' => $avatar,       //图片资源路径
            'left' => 335,
            'top' => 140,
            'stream' => 0,             //图片资源是否是字符串图像流
            'right' => 0,
            'bottom' => 0,
            'width' => 80,
            'height' => 80,
            'opacity' => 100
        ];

        $nick = $user['nick'];
        $fontSize = 18;
        $nickTextPos = imagettfbbox($fontSize, 0, $fontfile, $nick);
        $nickTextLineHeight = $nickTextPos[1] - $nickTextPos[7];
        $texts[] = [
            'text' => $nick,
            'left' => (750 - $nickTextPos[2]) / 2,
            'top' => 220 + 10 + $nickTextLineHeight,
            'fontPath' => $fontfile,     //字体文件
            'fontSize' => $fontSize,   //字号
            'fontColor' => '0,0,0',       //字体颜色
            'angle' => 0
        ];

        $str0 = "推荐一个真实、严肃、优质的相亲平台";
        $fontSize = 15;
        $str0Pos = imagettfbbox($fontSize, 0, $fontfile, $str0);
        $str0LineHeight = $str0Pos[1] - $str0Pos[7];
        $str0Top = 220 + 10 + $nickTextLineHeight + 50 + $str0LineHeight;
        $texts[] = [
            'text' => $str0,
            'left' => (750 - $str0Pos[2]) / 2,
            'top' => $str0Top,
            'fontPath' => $fontfile,     //字体文件
            'fontSize' => $fontSize,   //字号
            'fontColor' => '0,0,0',       //字体颜色
            'angle' => 0
        ];


        $fontfile2 = DOC_PATH . 'data/font/wangqiang-hand.ttf';
        $str1 = "这世上";
        $fontSize2 = 30;
        $str1Pos = imagettfbbox($fontSize2, 0, $fontfile2, $str1);
        $str1LineHeight = $str1Pos[1] - $str1Pos[7];
        $str1Top = 220 + 10 + $nickTextLineHeight + 150 + $str1LineHeight;
        $texts[] = [
            'text' => $str1,
            'left' => (750 - $str1Pos[2]) / 2,
            'top' => $str1Top,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize2,   //字号
            'fontColor' => '57,157,189',       //字体颜色
            'angle' => 0
        ];

        $str2 = "总有一个人";
        $str2Pos = imagettfbbox($fontSize2, 0, $fontfile2, $str2);
        $str2LineHeight = $str2Pos[1] - $str2Pos[7];
        $str2Top = $str1Top + 20 + $str2LineHeight;
        $texts[] = [
            'text' => $str2,
            'left' => (750 - $str2Pos[2]) / 2,
            'top' => $str2Top,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize2,   //字号
            'fontColor' => '57,157,189',       //字体颜色
            'angle' => 0
        ];

        $str3 = "在某个角落";
        $str3Pos = imagettfbbox($fontSize2, 0, $fontfile2, $str3);
        $str3LineHeight = $str3Pos[1] - $str3Pos[7];
        $str3Top = $str2Top + 20 + $str3LineHeight;
        $texts[] = [
            'text' => $str3,
            'left' => (750 - $str3Pos[2]) / 2,
            'top' => $str3Top,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize2,   //字号
            'fontColor' => '57,157,189',       //字体颜色
            'angle' => 0
        ];

        $str4 = "默默等着你";
        $str4Pos = imagettfbbox($fontSize2, 0, $fontfile2, $str4);
        $str4LineHeight = $str4Pos[1] - $str4Pos[7];
        $str4Top = $str3Top + 20 + $str4LineHeight;
        $texts[] = [
            'text' => $str4,
            'left' => (750 - $str4Pos[2]) / 2,
            'top' => $str4Top,
            'fontPath' => $fontfile2,     //字体文件
            'fontSize' => $fontSize2,   //字号
            'fontColor' => '57,157,189',       //字体颜色
            'angle' => 0
        ];

        // 生成二维码
        $mpSite = $this->getSiteConfigService()->getValueByCode('mp_site');
        require_once EXTEND_PATH . 'vm/org/phpqrcode.php';
        $qrUrl = $mpSite . '?fromuid=' . $userId;
        $qrFile = $tempDir . 'qrcode/' . time() . '_' . rand_string(6) . '.png';
        if(!is_dir(dirname($qrFile))) {
            makeDir(dirname($qrFile));
        }
        \QRcode::png($qrUrl, $qrFile);
        $images[] = [
            'url' => $qrFile,       //图片资源路径
            'left' => 220,
            'top' => 790,
            'stream' => 0,             //图片资源是否是字符串图像流
            'right' => 0,
            'bottom' => 0,
            'width' => 140,
            'height' => 140,
            'opacity' => 100
        ];

        $config = [
            'image' => $images,
            'text' => $texts,
            'background' => DOC_PATH . 'data/images/share_poster_6.jpg'
        ];
        createPoster($config, WWW_PATH . $path);
        return $url;
    }

    public function myQrCodeImg($userId)
    {
        $hash = md5($userId);
        $path = 'uploads/share_qrcode/' . $hash{0} . '/' . $hash{1} . '/' . $userId . '.jpg';
        $url = request()->scheme() . '://' . request()->host() . '/' . getContextPath() . $path;
        if (is_file(WWW_PATH . $path)) {
            return $url;
        }
        if (!is_dir(dirname(WWW_PATH . $path))) {
            makeDir(dirname(WWW_PATH . $path));
        }
        // 生成二维码
        $mpSite = $this->getSiteConfigService()->getValueByCode('mp_site');
        require_once EXTEND_PATH . 'vm/org/phpqrcode.php';
        $qrUrl = $mpSite . '?fromuid=' . $userId;
        $qrFile = WWW_PATH . $path;
        \QRcode::png($qrUrl, $qrFile);
        return $url;
    }

    public function onRefreshUserVipLevel()
    {
        $lockKey = 'refresh_marriage_user_vip_level';
        $lock = DisLockFactory::instance()->lock($lockKey, 10000);
        if(!$lock) {
            throw new Exception('请重试');
        }
        try {
            $nowtime = time();
            $params = [
                'vip_level' => ['>', 0],
                'vip_level_end_time' => ['<', $nowtime]
            ];
            $res = $this->pageListByParams($params, 20, ['page' => 1], ['vip_level_end_time' => 'ASC']);
            if(!empty($res['data'])) {
                $site = config('site');
                $vipLevels = $site['vip_levels'];
                $queueConfig = config('queue');
                $queueHandler = QueueFactory::instance();
                $wechatConfig = config('wechat');
                $msgTemplateId = $wechatConfig['mp_msg_templates']['vip_level_update_notice'];
                foreach ($res['data'] as $item) {
                    $oldVipName = '';
                    foreach ($vipLevels as $vipLevelItem) {
                        if($vipLevelItem['value'] == $item['vip_level']) {
                            $oldVipName = $vipLevelItem['name'];
                            break;
                        }
                    }
                    $this->update([
                        'vip_level' => 0,
                        'vip_level_begin_time' => 0,
                        'vip_level_end_time' => 0
                    ], [
                        'id' => $item['id'],
//                        'vip_level' => ['>', 0],
//                        'vip_level_end_time' => ['<', $nowtime]
                    ]);

                    // 发送通知
                    $systemNoticeId = $this->getSystemNoticeService()->create([
                        'title' => '您的vip已过期',
                        'content' => '您的vip会员已过期，请及时升级。',
                        'type' => SystemNotice::TYPE_SINGLE,
                        'status' => SystemNotice::STATUS_PULLED,
                        'recipient_id' => $item['user_id'],
                        'manager_id' => 0,
                        'url' => json_encode([
                            'weapp' => '/pages/vip/buy',
                            'web' => '/vip_buy',
                            'app' => '/vip/buy'
                        ])
                    ]);
                    $this->getUserSystemNoticeService()->create([
                        'system_notice_id' => $systemNoticeId,
                        'recipient_id' => $item['user_id'],
                        'status' => UserSystemNotice::STATUS_WAIT_READ,
                        'pull_time' => time()
                    ]);

                    // 给被申请人发送公众号通知
                    try {
                        if($this->getUserPlatformService()->checkUserSubscribedMpAccount($item['user_id'])) {
                            $userPlatform = $this->getUserPlatformService()->info([
                                'user_id' => $item['user_id'],
                                'platform' => UserPlatform::PLATFORM_WX_MP
                            ]);
                            if($userPlatform) {
                                $openid = $userPlatform['open_id'];
                                $msgData = [
                                    'first' => [
                                        'value' => '您的vip会员已过期'
                                    ],
                                    'keyword1' => [
                                        'value' => $oldVipName
                                    ],
                                    'keyword2' => [
                                        'value' => '普通用户'
                                    ],
                                    'keyword3' => [
                                        'value' => date('Y-m-d H:i:s', $item['vip_level_end_time'])
                                    ],
                                    'remark' => [
                                        'value' => '请及时重新开通vip会员'
                                    ]
                                ];
                                $url = $this->getSiteConfigService()->getValueByCode('mp_site') . '/vip_buy';
                                $miniprogram = null;

                                $queueHandler->set($queueConfig['queues']['mp_msg'], [
                                    'openid' => $openid,
                                    'template_id' => $msgTemplateId,
                                    'data' => $msgData,
                                    'url' => $url,
                                    'miniprogram' => $miniprogram
                                ]);
                            }
                        }
                    } catch (\Exception $e) {
                        $log = 'FILE:' . $e->getFile() . "\r\n" . 'LINE:' . $e->getLine(). "\r\n" . 'MSG:' . $e->getMessage();
                        Log::error($log);
                    }
                }
            }
        } catch (\Exception $e) {
            $log = 'FILE:' . $e->getFile() . "\r\n" . 'LINE:' . $e->getLine(). "\r\n" . 'MSG:' . $e->getMessage();
            Log::error($log);
        } finally {
            DisLockFactory::instance()->unlock($lockKey);
        }
    }
}